load("../src/includes.js");

DataCenterConf = {
	racks: [{name: 'r1'}, {name: 'r2'}],
	switches: [
		{name: 'sw1', ports: 10, speed: 100}],
	hosts: [
		{name: 'nn', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['namenode']},
		{name: 'dn1', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['datanode']},
		{name: 'dn2', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['datanode']},
		{name: 'dn3', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['datanode']},
		{name: 'dn4', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['datanode']},
		{name: 'dn5', disk: 'disk1', connect: 'sw1', rack: 'r2', apps: ['datanode']},
		{name: 'dn6', disk: 'disk1', connect: 'sw1', rack: 'r2', apps: ['datanode']},
		{name: 'dn7', disk: 'disk1', connect: 'sw1', rack: 'r2', apps: ['datanode']},
		{name: 'dn8', disk: 'disk1', connect: 'sw1', rack: 'r2', apps: ['datanode']},
		{name: 'client', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['hdfsclient']}],
	disks: [{name: 'disk1', capacity: 100e9, used: 4e9,
    	   accessTime: 1, readThput: 100, writeThput: 100, nDisks: 1}]
};

function test(seed, nreplica, writer) {
	nreplica = nreplica ? nreplica : 3;
	writer = writer ? writer : 'client';
	var dc = new DataCenter(seed);
	dc.load(DataCenterConf);
	var a = Placement.chooseTarget(dc, nreplica, dc.getHost(writer), null, null, 100);
	var results = [];
	for (var i in a) { results.push(a[i].name + "(" + a[i].rack.name + ")");}
	print(results);
}

for (var i = 0; i < 10; i ++) {
	test(i, 4, 'dn5');
}